#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>

#define PATH_2 "/proc/cpuinfo"

int get_ID(char *buf_3)
{
	int 		           fd=-1;
	char 		           buf[2048];
	char                   buf_2[128];
	char	       	       *str=NULL;
	char                   *ptr=NULL;
	char                   *rtr=NULL;
	int			           found=0;
	int                    i=0;
	int                    rv=-1;

	memset(buf,0,sizeof(buf));	
	memset(buf_2,0,sizeof(buf_2));
	memset(buf_3,0,sizeof(buf_3));

	fd = open(PATH_2, O_RDONLY);
	if (!fd)
	{
		perror("FILE problem");
		return -1;
	}

	rv=read(fd,buf,sizeof(buf));
	if(rv<0)
	{
		printf("Read failure:%s\n", strerror(errno));
		return -2;
	}

	str=strstr(buf,"Hardware");
	if(!str)
	{
		printf("can't not find string\n");
		return -3;
	}

	ptr=strstr(str,"B");
	if(!str)
	{
		printf("can't not find string\n");
		return -4;
	}

	rtr=strstr(ptr,"R");
	if(!str)
	{
		printf("can't not find string\n");
		return -5;
	}

	strncpy(buf_3, ptr, strlen(ptr)-strlen(rtr));
	close(fd);
	return 0;
}

